package com.yunji.coupon.engine;

import com.yunji.coupon.dto.CouponTmplCreateDTO;
import com.yunji.coupon.enums.ValidTimeTypeEnum;
import org.springframework.util.Assert;

/**
 * @author : peter-zhu
 * @date : 2024/10/25 22:49
 * @description : 优惠券校验
 **/
public class CouponValidate {
    public static void validateCouponTmpl(CouponTmplCreateDTO dto) {
        if (ValidTimeTypeEnum.REGULAR.getCode().equals(dto.getValidTimeType())) {
            Assert.isTrue(dto.getValidPeriodS() != null || dto.getValidPeriodE() != null, "固定类型必须填写有效日期");
        } else if (ValidTimeTypeEnum.NOW.getCode().equals(dto.getValidTimeType())) {
            Assert.isTrue(dto.getValidDays() != null, "领取当日起必须填写几日后领取");
        } else {
            throw new RuntimeException("领取时间类型错误");
        }
    }
}
